package com.hmall.search.web.controller;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.SearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 搜索业务层
 *
 * @Author Eeyore
 * @Date 2022/8/10 17:32
 * @Description: 搜索业务层
 */
@Slf4j
@RestController
@RequestMapping("search")
public class SearchController {

    @Autowired
    SearchService searchService;

    /**
     * 搜索框自动补全
     *
     * @param key
     * @return
     */
    @GetMapping("suggestion")
    public List<String> suggestion(@RequestParam("key") String key) {
//        log.warn("补全功能中获取到的key值为:{}", key);
        return searchService.getSuggestion(key);
    }

    /**
     * 条件过滤查询
     * @param params
     * @return
     */
    @PostMapping("filters")
    public Map<String, List<String>> filters(@RequestBody RequestParams params) {
        return searchService.filters(params);
    }

    @PostMapping("list")
    public PageDTO<ItemDoc> getList(@RequestBody RequestParams params){
        return searchService.getList(params);
    }
}